package com.woniuxy.purchasemanager.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.commons.entity.purchaseManager.NeedAllocationEntity;
import com.woniuxy.commons.entity.purchaseManager.NeedAndGoodsEntity;
import com.woniuxy.commons.entity.purchaseManager.base.VoEntity;
import com.woniuxy.commons.result.Result;
import com.woniuxy.purchasemanager.service.NeedAllocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 需求分配
 *
 * @author huangzhichao
 * @email 1205560871@gmail.com
 * @date 2022-04-19 13:00:28
 */
@Api(tags = "需求分配")
@RestController
@RequestMapping("/need/needallocation")
public class NeedAllocationController {
    @Autowired(required=false)
    private NeedAllocationService needAllocationService;

    /**
     * 列表
     */


    @ApiOperation(value = "列表")
    @GetMapping("/listAll/{currentPage}/{pageSize}")
    public Result list(@PathVariable("currentPage") Integer currentPage,@PathVariable("pageSize") Integer pageSize) {
        VoEntity<NeedAllocationEntity> needDemandGoods = needAllocationService.pageListAll(currentPage,pageSize);
        return Result.ok(needDemandGoods);
    }

    /**
     * 分配需求单导出列表
     * @Author: xianhao
     * @Date: 2022/4/22 15:52
     * @return: com.woniuxy.commons.result.Result<java.util.List<com.woniuxy.commons.entity.purchaseManager.NeedAllocationEntity>>
     **/
    @ApiOperation(value ="配需求单导出列表")
    @GetMapping("/all")
    public Result<List<NeedAllocationEntity>> selectAll(){
        return Result.ok(needAllocationService.list(new QueryWrapper<>()));
    }

    /**
     * 信息
     */
    @ApiOperation(value ="信息")
    @GetMapping ("/info/{id}")
    public Result info(@PathVariable("id") Integer id){
		NeedAllocationEntity needAllocation = needAllocationService.getById(id);

        return Result.ok(needAllocation);
    }

    /**
     * 保存
     */
    @ApiOperation(value ="保存")
    @PostMapping("/save")
    public Result save(@RequestBody NeedAllocationEntity needAllocation){
        needAllocationService.save(needAllocation);
        return Result.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value ="修改")
    @PostMapping("/update")
    public Result update(@RequestBody NeedAllocationEntity needAllocation){
		needAllocationService.updateById(needAllocation);

        return Result.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value ="删除")
    @DeleteMapping ("/delete")
    public Result delete(@RequestBody Integer[] ids){
		needAllocationService.removeByIds(Arrays.asList(ids));

        return Result.ok();
    }

    /**
     * 查询对应需求单单号商品详情
     */
    @ApiOperation(value = "需求分配单详情")
    @GetMapping(value = "/getOrderGoodsList/{id}")
    public Result getOrderGoodsList(@PathVariable("id") String needOrderId){

        Map<String, Object> map =  needAllocationService.getOrderGoodsList(needOrderId);
        return Result.ok(map);
    }
    @ApiOperation(value = "需求分配单")
    @PostMapping(value = "/addOrder")
    public Result ADDOrderGoodsList(@RequestBody Map<String,Object> map){
        boolean isOk = needAllocationService.addList(map);
        return  Result.ok(isOk);
    }
}
